﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MxWeiXinPF.Common;

namespace MxWeiXinPF.Web.shopmgr.coupon
{
    public partial class coupon_list : MxWeiXinPF.Web.UI.ManagePage
    {
        protected MxWeiXinPF.Model.manager admin_info;
        private MxWeiXinPF.BLL.wx_shop_coupon caBll = new MxWeiXinPF.BLL.wx_shop_coupon();
        protected int catalogId = 0;
        protected int category_id;
        protected string keywords = string.Empty;
        protected int page;
        protected int pageSize;
        protected int shopid = 0;
        protected int totalCount;
        protected int selectshopid;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                this.keywords = MXRequest.GetQueryString("keywords");
                this.category_id = MXRequest.GetQueryInt("category_id");
                this.pageSize = this.GetPageSize(10);
                this.selectshopid = MXRequest.GetQueryInt("selectshopid");
                if (!this.Page.IsPostBack)
                {
                    this.admin_info = base.GetAdminInfo();
                    //this.btnDelete.Visible = ChkAdminLevelEx("onlineproduct", MXEnums.ActionEnum.Edit.ToString());
                    this.TreeBind();
                    this.RptBind(this.CombSqlTxt(this.keywords), "id asc");
                }
            }
            catch (Exception ex)
            {

            }
        }
        private void RptBind(string _strWhere, string _orderby)
        {
            int num15 = 0;
            if (GetRelativeAdminInfo() != null)
            {
                num15 = GetRelativeAdminInfo().id;
            }
            else
            {
                num15 = GetAdminInfo().id;
            }

            this.lblWid.Text = num15.ToString();
            this.page = MXRequest.GetQueryInt("page", 1);
            //this.txtKeywords.Text = this.keywords;

            DataSet set = this.caBll.GetList(this.pageSize, this.page, _strWhere, _orderby, out this.totalCount);
            this.rptList.DataSource = set;
            this.rptList.DataBind();
            this.txtPageNum.Text = this.pageSize.ToString();
            string linkUrl = Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&page={2}&selectshopid={3}", new string[] { "0", this.keywords, "__id__", this.selectshopid.ToString() });
            this.PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, linkUrl, 8);
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int num = 0;
            int num2 = 0;
            for (int i = 0; i < this.rptList.Items.Count; i++)
            {
                int id = Convert.ToInt32(((HiddenField)this.rptList.Items[i].FindControl("hidId")).Value);
                CheckBox box = (CheckBox)this.rptList.Items[i].FindControl("chkId");
                if (box.Checked)
                {
                    if (this.caBll.Delete(id))
                    {
                        num++;
                    }
                    else
                    {
                        num2++;
                    }
                }
            }
            base.AddAdminLog(MXEnums.ActionEnum.Delete.ToString(), string.Concat(new object[] { "删除优惠券信息", num, "条，失败", num2, "条" }));
            base.JscriptMsg(string.Concat(new object[] { "删除成功", num, "条，失败", num2, "条！" }), Utils.CombUrlTxt("coupon_list.aspx", "category_id={0}&keywords={1}&selectshopid={2}", new string[] { this.category_id.ToString(), this.keywords, this.selectshopid.ToString() }), "Success");
        }
        private void TreeBind()
        {
        }

        protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
        { }

        protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        { }
        protected string CombSqlTxt(string _keywords)
        {
            return "";
        }
        private int GetPageSize(int _default_size)
        {
            int num;
            if (int.TryParse(Utils.GetCookie("couponlist_page_size"), out num) && (num > 0))
            {
                return num;
            }
            return _default_size;
        }

        protected void txtPageCount_TextChanged(object sender, EventArgs e)
        {
            base.Response.Redirect(Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&page={2}&selectshopid={3}", new string[] { this.category_id.ToString(), "", this.txtPageCount.Text.Trim(), this.selectshopid.ToString() }));
        }

        protected void txtPageNum_TextChanged(object sender, EventArgs e)
        {
            int num;
            if (int.TryParse(this.txtPageNum.Text.Trim(), out num) && (num > 0))
            {
                Utils.WriteCookie("productOnSale_page_size", num.ToString(), 0x3840);
            }
            base.Response.Redirect(Utils.CombUrlTxt("productOnSale.aspx", "category_id={0}&keywords={1}&selectshopid={2}", new string[] { this.category_id.ToString(), this.keywords, this.selectshopid.ToString() }));
        }
        protected string GetState(string state)
        {
            if (state == "0")
            {
                return "未启用";
            }
            return "已启用";
        }
    }
}